/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.ipo.mm.web.formbeans;

import java.text.SimpleDateFormat;
import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.ipo.mm.ejb.entities.Actions;
import org.ipo.mm.web.util.ConstantManager;

/**
 *
 * @author makcro
 */
public class ActionBean extends org.apache.struts.validator.ValidatorForm {

    private String actionId;
    private String actionName;
    private String actionDesc;
    private String actionDueDate;
    private String actionStatus;
    private String operation;

    public String getOperation() {
        return operation;
    }

    public void setOperation(String operation) {
        this.operation = operation;
    }

    public String getActionDesc() {
        return actionDesc;
    }

    public void setActionDesc(String actionDesc) {
        this.actionDesc = actionDesc;
    }

    public String getActionDueDate() {
        return actionDueDate;
    }

    public void setActionDueDate(String actionDueDate) {
        this.actionDueDate = actionDueDate;
    }

    public String getActionName() {
        return actionName;
    }

    public void setActionName(String actionName) {
        this.actionName = actionName;
    }

    public String getActionStatus() {
        return actionStatus;
    }

    public void setActionStatus(String actionStatus) {
        this.actionStatus = actionStatus;
    }

    /**
     *
     */
    public ActionBean() {
        super();
        // TODO Auto-generated constructor stub
    }

    @Override
    public void reset(ActionMapping mapping, HttpServletRequest request) {

        String method = request.getParameter("method");
        String updateMethodCall = "showUpdateActionsForm";
        String createMethodCall = "showCreateActionsForm";

        if (updateMethodCall.equals(method)) {
            Actions actions = (Actions) request.getSession().getAttribute(ConstantManager.SESSION_ACTIONS_PROCESS);

            if (actions != null) {

                setActionDesc(actions.getActionText() != null ? actions.getActionText() : "");
                setActionDueDate(actions.getDueDate() != null ? new SimpleDateFormat("dd/MM/yyyy").format(actions.getDueDate()) : "");
                setActionName(actions.getName() != null ? actions.getName() : "");
                setActionStatus(actions.getStatus());



            }

        }

        else if(createMethodCall.equals(method)){
            setActionDesc(null);
            setActionDueDate(null);
            setActionName(null);
            setActionStatus(null);
        }




    }

    public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
        ActionErrors errors = super.validate(mapping, request);

        return errors;
    }

    /**
     * @return the actionId
     */
    public String getActionId() {
        return actionId;
    }

    /**
     * @param actionId the actionId to set
     */
    public void setActionId(String actionId) {
        this.actionId = actionId;
    }
}
